import numpy as np
from sklearn.model_selection import train_test_split
x=np.array([[19,30],[30,40],[39,47],[40,52],[47,50],[50,55],[60,60],[62,65],[73,70],[75,82],[77,85],[90,95],[92,90]])
y=np.array([0,0,0,0,0,0,1,1,1,1,1,1,1])
x_train,x_test,y_train,y_test = train_test_split
k_range =range(2,11)
k_error =[]
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import cross_val_score
for k in k_range:
    model = KNeighborsClassifier(n_neighbors=k)
    scores = cross_val_score(model,x,y,cv=5,scoring='accuracy')
    k_error.append(1 - scores.mean())
import matplotlib.pyplot as plt
plt.plot(k_range,k_range)
plt.xlabel('k值')
plt.ylabel('预测误差率')
plt.show()